package code.temp.log;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <b>Description : </b>
 *
 * @author CPF
 * @date 2020/12/4 0:36
 **/
public class CodeTest {

    static final Charset[] charsets = new Charset[]{StandardCharsets.UTF_8, Charset.forName("GBK")};

    static final String INFO = "0信1息2信息3";

    @Data
    @AllArgsConstructor
    public static class Bean {
        Charset encode;
        Charset decode;
        String val;
        public String toString() {
            return this.encode + "=" + this.decode;
        }
    }

    public static void main(String[] args) {
        List<Bean> list = new ArrayList<>();
        for (Charset charset1 : charsets) {
            for (Charset charset2 : charsets) {
                list.add(new Bean(charset1, charset2, new String(INFO.getBytes(charset1), charset2)));
                System.out.println(charset1 + "\t" + charset2 + "\t" + new String(INFO.getBytes(charset1), charset2));
            }
        }
        list.stream().collect(Collectors.groupingBy(Bean::getVal)).forEach((k, v) -> System.out.println(k + "\t\t ==> " + v));

    }

}
